<?php
	for($i=1;$i<=$_SESSION["count"];$i++)
	{
		if(isset($_SESSION["sp_id"][$i])&&isset($_SESSION["soluong"][$i]))
		{
	$ma = $_SESSION["sp_id"][$i];
	$sql = "select * from sp where sp_id = '".$ma."'";
	$result = DataProvider::ExecuteQuery($sql);
	$row = mysql_fetch_array($result);
	$tongtien += ($row["sp_gia"] * $_SESSION["soluong"][$i]) + ($row["sp_sall"]* $_SESSION["soluong"][$i]);
	$tongsluong += $_SESSION["soluong"][$i];
	$tbgia = $tongtien/$tongsluong;
	$sql ='select * from sp where sp_id = "'.$_SESSION["sp_id"][$i].'" ';
	$resul1t = DataProvider::ExecuteQuery($sql);
	$dong = mysql_fetch_array($resul1t);
	$sql ='select * from user where username = "'.$_SESSION["User"].'" ';
	$resul2t = DataProvider::ExecuteQuery($sql);
	$row1 = mysql_fetch_array($resul2t);
	$khang = $row1["fullname"].' - Địa Chỉ: '.$row1["address"].' - Số ĐT: '.$row1["cellphone"];
	$soluong1 = $_SESSION["soluong"][$i];
		}
	}
	$flag = 0;
	if(!isset($_SESSION["count"]))
		$_SESSION["count"] = 1;
	if(isset($_REQUEST["sp_id"]))
	{
		$maloaisanpham = $_REQUEST["sp_id"];
			for($i=1;$i<=$_SESSION["count"];$i++)
			{
				if($_SESSION["sp_id"][$i] == $maloaisanpham)
				{
					$_SESSION["soluong"][$i] ++;
				header("location:home.php?typ=product&act=seecart");
					$flag = 1;
				}
			}
			if($flag == 0)
			{
				$_SESSION["sp_id"][$_SESSION["count"]] =  $maloaisanpham;
				$_SESSION["soluong"][$_SESSION["count"]] = 1;
				$_SESSION["count"]++;
				//echo $_SESSION["count"];
				header("location:home.php?typ=product&act=seecart");
			}
	}
?>
